{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4affc634",
   "metadata": {},
   "source": [
    "# `geomCurve()`\n",
    "\n",
    "\n",
    "Specific arguments:\n",
    "\n",
    "* `curvature` A numeric value that indicates the amount of curvature. Negative values produce left-hand curves, positive values produce right-hand curves and zero produces a straight line. Default = 0.5.\n",
    "\n",
    "* `angle` A numeric value between 0 and 180 that indicates the amount by which the control points of the curve should be skewed. Values less than 90 skew the curve towards the start point and values greater than 90 skew the curve towards the end point. Default = 90.\n",
    "\n",
    "* `ncp` The number of control points used to draw the curve. More control points produce a smoother curve. Default = 5."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "77516fb8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "            <div id=\"kotlin_out_0\"/>\n",
       "            <script type=\"text/javascript\">\n",
       "                            if(!window.kotlinQueues) {\n",
       "                window.kotlinQueues = {};\n",
       "            }\n",
       "            if(!window.kotlinQueues[\"DataFrame\"]) {\n",
       "                var resQueue = [];\n",
       "                window.kotlinQueues[\"DataFrame\"] = resQueue;\n",
       "                window[\"call_DataFrame\"] = function(f) {\n",
       "                    resQueue.push(f);\n",
       "                }\n",
       "            }\n",
       "            (function (){\n",
       "                var modifiers = [(function(script) {\n",
       "    script.src = \"https://cdn.jsdelivr.net/gh/Kotlin/dataframe@d6467c1389bc031958acd5310fce39167b5cc581/src/main/resources/init.js\"\n",
       "    script.type = \"text/javascript\";\n",
       "})];\n",
       "                var e = document.getElementById(\"kotlin_out_0\");\n",
       "                modifiers.forEach(function (gen) {\n",
       "                    var script = document.createElement(\"script\");\n",
       "                    gen(script)\n",
       "                    script.addEventListener(\"load\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {f();};\n",
       "                        window.kotlinQueues[\"DataFrame\"].forEach(function(f) {f();});\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                    }, false);\n",
       "                    script.addEventListener(\"error\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {};\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                        var div = document.createElement(\"div\");\n",
       "                        div.style.color = 'darkred';\n",
       "                        div.textContent = 'Error loading resource DataFrame';\n",
       "                        document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
       "                    }, false);\n",
       "                    \n",
       "                    e.appendChild(script);\n",
       "                });\n",
       "            })();\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "                <style>\n",
       "                :root {\n",
       "    --background: #fff;\n",
       "    --background-odd: #f5f5f5;\n",
       "    --background-hover: #d9edfd;\n",
       "    --header-text-color: #474747;\n",
       "    --text-color: #848484;\n",
       "    --text-color-dark: #000;\n",
       "    --text-color-medium: #737373;\n",
       "    --text-color-pale: #b3b3b3;\n",
       "    --inner-border-color: #aaa;\n",
       "    --bold-border-color: #000;\n",
       "    --link-color: #296eaa;\n",
       "    --link-color-pale: #296eaa;\n",
       "    --link-hover: #1a466c;\n",
       "}\n",
       "\n",
       ":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"]{\n",
       "    --background: #303030;\n",
       "    --background-odd: #3c3c3c;\n",
       "    --background-hover: #464646;\n",
       "    --header-text-color: #dddddd;\n",
       "    --text-color: #b3b3b3;\n",
       "    --text-color-dark: #dddddd;\n",
       "    --text-color-medium: #b2b2b2;\n",
       "    --text-color-pale: #737373;\n",
       "    --inner-border-color: #707070;\n",
       "    --bold-border-color: #777777;\n",
       "    --link-color: #008dc0;\n",
       "    --link-color-pale: #97e1fb;\n",
       "    --link-hover: #00688e;\n",
       "}\n",
       "\n",
       "table.dataframe {\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 12px;\n",
       "    background-color: var(--background);\n",
       "    color: var(--text-color-dark);\n",
       "    border: none;\n",
       "    border-collapse: collapse;\n",
       "}\n",
       "\n",
       "table.dataframe th, td {\n",
       "    padding: 6px;\n",
       "    border: 1px solid transparent;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       "table.dataframe th {\n",
       "    background-color: var(--background);\n",
       "    color: var(--header-text-color);\n",
       "}\n",
       "\n",
       "table.dataframe td {\n",
       "    vertical-align: top;\n",
       "}\n",
       "\n",
       "table.dataframe th.bottomBorder {\n",
       "    border-bottom-color: var(--bold-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(odd) {\n",
       "    background: var(--background-odd);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(even) {\n",
       "    background: var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:hover {\n",
       "    background: var(--background-hover);\n",
       "}\n",
       "\n",
       "table.dataframe a {\n",
       "    cursor: pointer;\n",
       "    color: var(--link-color);\n",
       "    text-decoration: none;\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover > td a {\n",
       "    color: var(--link-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe a:hover {\n",
       "    color: var(--link-hover);\n",
       "    text-decoration: underline;\n",
       "}\n",
       "\n",
       "table.dataframe img {\n",
       "    max-width: fit-content;\n",
       "}\n",
       "\n",
       "table.dataframe th.complex {\n",
       "    background-color: var(--background);\n",
       "    border: 1px solid var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe .leftBorder {\n",
       "    border-left-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightBorder {\n",
       "    border-right-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightAlign {\n",
       "    text-align: right;\n",
       "}\n",
       "\n",
       "table.dataframe .expanderSvg {\n",
       "    width: 8px;\n",
       "    height: 8px;\n",
       "    margin-right: 3px;\n",
       "}\n",
       "\n",
       "table.dataframe .expander {\n",
       "    display: flex;\n",
       "    align-items: center;\n",
       "}\n",
       "\n",
       "/* formatting */\n",
       "\n",
       "table.dataframe .null {\n",
       "    color: var(--text-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe .structural {\n",
       "    color: var(--text-color-medium);\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .dataFrameCaption {\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .numbers {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe td:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "\n",
       "                </style>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "   <div id=\"gEjgce\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.3.0rc1/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"gEjgce\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"gEjgce\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot\n",
    "%use dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6c0c68e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.0.0.0-SNAPSHOT. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.0rc1."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ea7fe3f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "fun curvePlot(curvature: Number = 0.5, angle: Number = 90, ncp: Int = 5) = \n",
    "    letsPlot() + \n",
    "            geomCurve(x = -10, y = 1, xend = 10, yend = -1, \n",
    "                      curvature = curvature, angle = angle, ncp = ncp,\n",
    "                      arrow = arrow(ends = \"both\")) +\n",
    "            ggtitle(\"curvature=$curvature, angle=$angle, ncp=$ncp\") +\n",
    "            xlim(-15 to 15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2e8519d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"qMBhnG\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":3,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"ends\":\"both\"\n",
       "},\n",
       "\"x\":-10.0,\n",
       "\"y\":1.0,\n",
       "\"angle\":0.0,\n",
       "\"yend\":-1.0,\n",
       "\"ncp\":5.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":10.0,\n",
       "\"geom\":\"curve\",\n",
       "\"curvature\":0.5,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"ggtitle\":{\n",
       "\"text\":\"curvature=0.5, angle=0, ncp=5\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-15.0,15.0]\n",
       "}]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"ends\":\"both\"\n",
       "},\n",
       "\"x\":-10.0,\n",
       "\"y\":1.0,\n",
       "\"angle\":90.0,\n",
       "\"yend\":-1.0,\n",
       "\"ncp\":1.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":10.0,\n",
       "\"geom\":\"curve\",\n",
       "\"curvature\":0.5,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"ggtitle\":{\n",
       "\"text\":\"curvature=0.5, angle=90, ncp=1\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-15.0,15.0]\n",
       "}]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"ends\":\"both\"\n",
       "},\n",
       "\"x\":-10.0,\n",
       "\"y\":1.0,\n",
       "\"angle\":45.0,\n",
       "\"yend\":-1.0,\n",
       "\"ncp\":5.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":10.0,\n",
       "\"geom\":\"curve\",\n",
       "\"curvature\":0.5,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"ggtitle\":{\n",
       "\"text\":\"curvature=0.5, angle=45, ncp=5\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-15.0,15.0]\n",
       "}]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"ends\":\"both\"\n",
       "},\n",
       "\"x\":-10.0,\n",
       "\"y\":1.0,\n",
       "\"angle\":45.0,\n",
       "\"yend\":-1.0,\n",
       "\"ncp\":5.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":10.0,\n",
       "\"geom\":\"curve\",\n",
       "\"curvature\":-1.0,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"ggtitle\":{\n",
       "\"text\":\"curvature=-1, angle=45, ncp=5\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-15.0,15.0]\n",
       "}]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"ends\":\"both\"\n",
       "},\n",
       "\"x\":-10.0,\n",
       "\"y\":1.0,\n",
       "\"angle\":30.0,\n",
       "\"yend\":-1.0,\n",
       "\"ncp\":5.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":10.0,\n",
       "\"geom\":\"curve\",\n",
       "\"curvature\":0.7,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"ggtitle\":{\n",
       "\"text\":\"curvature=0.7, angle=30, ncp=5\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-15.0,15.0]\n",
       "}]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"ends\":\"both\"\n",
       "},\n",
       "\"x\":-10.0,\n",
       "\"y\":1.0,\n",
       "\"angle\":30.0,\n",
       "\"yend\":-1.0,\n",
       "\"ncp\":5.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":10.0,\n",
       "\"geom\":\"curve\",\n",
       "\"curvature\":-0.7,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"ggtitle\":{\n",
       "\"text\":\"curvature=-0.7, angle=30, ncp=5\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-15.0,15.0]\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"qMBhnG\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(\n",
    "    listOf(\n",
    "        curvePlot(angle = 0),\n",
    "        curvePlot(ncp = 1),\n",
    "        curvePlot(angle = 45),\n",
    "        curvePlot(curvature = -1, angle = 45),\n",
    "        curvePlot(curvature = 0.7, angle = 30),\n",
    "        curvePlot(curvature = -0.7, angle = 30)\n",
    "    ), \n",
    "    ncol = 2\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2f248ab",
   "metadata": {},
   "source": [
    "#### Annotate Objects on Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4cc04d14",
   "metadata": {},
   "outputs": [],
   "source": [
    "val mpgDf = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6facf377",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"tlf0UV\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"displ\",\n",
       "\"y\":\"hwy\"\n",
       "},\n",
       "\"data\":{\n",
       "\"displ\":[1.8,1.8,2.0,2.0,2.8,2.8,3.1,1.8,1.8,2.0,2.0,2.8,2.8,3.1,3.1,2.8,3.1,4.2,5.3,5.3,5.3,5.7,6.0,5.7,5.7,6.2,6.2,7.0,5.3,5.3,5.7,6.5,2.4,2.4,3.1,3.5,3.6,2.4,3.0,3.3,3.3,3.3,3.3,3.3,3.8,3.8,3.8,4.0,3.7,3.7,3.9,3.9,4.7,4.7,4.7,5.2,5.2,3.9,4.7,4.7,4.7,5.2,5.7,5.9,4.7,4.7,4.7,4.7,4.7,4.7,5.2,5.2,5.7,5.9,4.6,5.4,5.4,4.0,4.0,4.0,4.0,4.6,5.0,4.2,4.2,4.6,4.6,4.6,5.4,5.4,3.8,3.8,4.0,4.0,4.6,4.6,4.6,4.6,5.4,1.6,1.6,1.6,1.6,1.6,1.8,1.8,1.8,2.0,2.4,2.4,2.4,2.4,2.5,2.5,3.3,2.0,2.0,2.0,2.0,2.7,2.7,2.7,3.0,3.7,4.0,4.7,4.7,4.7,5.7,6.1,4.0,4.2,4.4,4.6,5.4,5.4,5.4,4.0,4.0,4.6,5.0,2.4,2.4,2.5,2.5,3.5,3.5,3.0,3.0,3.5,3.3,3.3,4.0,5.6,3.1,3.8,3.8,3.8,5.3,2.5,2.5,2.5,2.5,2.5,2.5,2.2,2.2,2.5,2.5,2.5,2.5,2.5,2.5,2.7,2.7,3.4,3.4,4.0,4.7,2.2,2.2,2.4,2.4,3.0,3.0,3.5,2.2,2.2,2.4,2.4,3.0,3.0,3.3,1.8,1.8,1.8,1.8,1.8,4.7,5.7,2.7,2.7,2.7,3.4,3.4,4.0,4.0,2.0,2.0,2.0,2.0,2.8,1.9,2.0,2.0,2.0,2.0,2.5,2.5,2.8,2.8,1.9,1.9,2.0,2.0,2.5,2.5,1.8,1.8,2.0,2.0,2.8,2.8,3.6],\n",
       "\"hwy\":[29.0,29.0,31.0,30.0,26.0,26.0,27.0,26.0,25.0,28.0,27.0,25.0,25.0,25.0,25.0,24.0,25.0,23.0,20.0,15.0,20.0,17.0,17.0,26.0,23.0,26.0,25.0,24.0,19.0,14.0,15.0,17.0,27.0,30.0,26.0,29.0,26.0,24.0,24.0,22.0,22.0,24.0,24.0,17.0,22.0,21.0,23.0,23.0,19.0,18.0,17.0,17.0,19.0,19.0,12.0,17.0,15.0,17.0,17.0,12.0,17.0,16.0,18.0,15.0,16.0,12.0,17.0,17.0,16.0,12.0,15.0,16.0,17.0,15.0,17.0,17.0,18.0,17.0,19.0,17.0,19.0,19.0,17.0,17.0,17.0,16.0,16.0,17.0,15.0,17.0,26.0,25.0,26.0,24.0,21.0,22.0,23.0,22.0,20.0,33.0,32.0,32.0,29.0,32.0,34.0,36.0,36.0,29.0,26.0,27.0,30.0,31.0,26.0,26.0,28.0,26.0,29.0,28.0,27.0,24.0,24.0,24.0,22.0,19.0,20.0,17.0,12.0,19.0,18.0,14.0,15.0,18.0,18.0,15.0,17.0,16.0,18.0,17.0,19.0,19.0,17.0,29.0,27.0,31.0,32.0,27.0,26.0,26.0,25.0,25.0,17.0,17.0,20.0,18.0,26.0,26.0,27.0,28.0,25.0,25.0,24.0,27.0,25.0,26.0,23.0,26.0,26.0,26.0,26.0,25.0,27.0,25.0,27.0,20.0,20.0,19.0,17.0,20.0,17.0,29.0,27.0,31.0,31.0,26.0,26.0,28.0,27.0,29.0,31.0,31.0,26.0,26.0,27.0,30.0,33.0,35.0,37.0,35.0,15.0,18.0,20.0,20.0,22.0,17.0,19.0,18.0,20.0,29.0,26.0,29.0,29.0,24.0,44.0,29.0,26.0,29.0,29.0,29.0,29.0,23.0,24.0,44.0,41.0,29.0,26.0,28.0,29.0,29.0,29.0,28.0,29.0,26.0,26.0,26.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"data\":{\n",
       "\"displ\":[2.5,2.5],\n",
       "\"hwy\":[28.0,29.0]\n",
       "},\n",
       "\"color\":\"#de77ae\",\n",
       "\"size\":5.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\"\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"nudge_x\":0.5,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"#c51b7d\",\n",
       "\"size\":10.0,\n",
       "\"x\":4.0,\n",
       "\"y\":40.0,\n",
       "\"position\":\"identity\",\n",
       "\"label\":\"Five-cylinder engine\",\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"data\":{\n",
       "\"displ\":[2.5,2.5],\n",
       "\"hwy\":[28.0,29.0]\n",
       "},\n",
       "\"color\":\"#c51b7d\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"angle\":15.0,\n",
       "\"length\":8.0,\n",
       "\"ends\":\"first\",\n",
       "\"type\":\"closed\"\n",
       "},\n",
       "\"geom\":\"curve\",\n",
       "\"curvature\":0.3,\n",
       "\"size\":0.3,\n",
       "\"yend\":40.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":4.0,\n",
       "\"size_end\":15.0,\n",
       "\"size_start\":6.0\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"tlf0UV\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val mpgCyl5 = mpgDf.filter { cyl == 5 && model == \"new beetle\" }.toMap()\n",
    "\n",
    "\n",
    "letsPlot(mpgDf.toMap()) { x = \"displ\"; y = \"hwy\" } +\n",
    "    geomPoint(data = mpgCyl5, color = \"#de77ae\", size = 5) +\n",
    "    geomPoint() + \n",
    "    geomText(label = \"Five-cylinder engine\", x = 4, y = 40, nudgeX = 0.5, color = \"#c51b7d\", size = 10) +\n",
    "    geomCurve(data = mpgCyl5, xend = 4, yend=40,\n",
    "              sizeStart = 6, sizeEnd = 15,\n",
    "              curvature = 0.3, arrow = arrow(length = 8, ends = \"first\", angle = 15, type = \"closed\"),\n",
    "              size = 0.3,\n",
    "              color=\"#c51b7d\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1e65abff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"OyiYrF\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"class\"\n",
       "},\n",
       "\"stat\":\"count\",\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"bar\",\n",
       "\"data\":{\n",
       "\"..count..\":[47.0,41.0,62.0,5.0,11.0,33.0,35.0],\n",
       "\"class\":[\"compact\",\"midsize\",\"suv\",\"2seater\",\"minivan\",\"pickup\",\"subcompact\"]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"length\":10.0,\n",
       "\"ends\":\"last\",\n",
       "\"type\":\"closed\"\n",
       "},\n",
       "\"x\":5.0,\n",
       "\"y\":55.0,\n",
       "\"yend\":6.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":3.0,\n",
       "\"geom\":\"curve\",\n",
       "\"size_start\":50.0,\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"x\":5.0,\n",
       "\"y\":55.0,\n",
       "\"position\":\"identity\",\n",
       "\"label\":\"Zoom Zoom!\",\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"OyiYrF\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ggplot(mpgDf.toMap()) + \n",
    "    geomBar() { x = \"class\" } +\n",
    "    geomCurve(x = 5, y = 55, xend = 3, yend = 6,\n",
    "              sizeStart = 50,\n",
    "              arrow = arrow(length = 10, ends = \"last\", type = \"closed\")) +\n",
    "    geomText(label = \"Zoom Zoom!\", x = 5, y = 55)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.8.0-dev-3517"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
